/*
 * Copyright (C) 2009 Rob Cash
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * SubscriptionStoreFactory.java
 * 
 * Created on Jan 6, 2009 at 7:32:32 PM
 */

package org.robcash.apps.messagepopup.vo;


import org.robcash.apps.messagepopup.MessageException;
import org.robcash.apps.messagepopup.vo.impl.SubscriptionStoreImpl;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;

/**
 * Factory bean to get an instance of a SubscriptionStore for the current user
 * @author Rob
 */
public class SubscriptionStoreFactory implements BeanFactoryAware {

    /**
     * Spring bean factory
     */
    private BeanFactory beanFactory;

    /**
     * Get a user-specific instance of a SubscriptionStore
     * @return Current user's subscription store
     */
    public static SubscriptionStoreFactory newInstance() {
        return new SubscriptionStoreFactory();
    }

    /**
     * Protected constructor
     */
    protected SubscriptionStoreFactory() {}

    /**
     * Set the Spring bean factory
     * @param factory Spring bean factory that created this instance
     */
    public void setBeanFactory(BeanFactory factory) {
        this.beanFactory = factory;
    }

    /**
     * Get a new instance of a SubscriptionStore
     * @return Current user's subscription store
     * @throws MessageException Thrown if a new instance cannot be instantiated
     */
    public SubscriptionStore newSubscriptionStore() throws MessageException {
//        return (SubscriptionStore) beanFactory.getBean(SUBSCRIPTION_STORE_BEAN_NAME);
        return new SubscriptionStoreImpl();
    }

}
